package resfoods.controller;

import com.yc.api.CartApi;
import com.yc.entity.MemberInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import resfoods.biz.MemberBiz;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("member")
public class MemberController {
    @Autowired
    private MemberBiz memberBiz;

    @Autowired
    private CartApi cartApi;

    @RequestMapping(value = "updateOrder", method = RequestMethod.GET)
    public int updateOrder(@RequestParam String ono, @RequestParam String ano, HttpSession session) {
        String o = ono;
        String a = ano;
        String ono1 = o.replace("\"", "");
        String ano1 = a.replace("\"", "");
        int result = 0;
        try {
            result = memberBiz.updateOrder(ano1,ono1);
            MemberInfo member = (MemberInfo) session.getAttribute("user");
            List<Map<String, Object>> carts = cartApi.findByMno(member.getMno());
            session.setAttribute("cartList", carts);
        } catch (Exception throwables) {
            throwables.printStackTrace();
        }
        return result;
    }
}
